package cn.com.sparkle.paxos.client;

import com.google.protobuf.GeneratedMessage;

import cn.com.sparkle.paxos.client.PaxosClient.CommandCallBack;
import cn.com.sparkle.paxos.iomodel.protobuffmessage.PaxosMessages.MessagePackage;
import cn.com.sparkle.paxos.net.NetNode;

public class Command {
	private GeneratedMessage request;
	private CommandCallBack callBack;

	public Command(GeneratedMessage request, CommandCallBack callBack) {
		super();
		this.request = request;
		this.callBack = callBack;
	}

	public GeneratedMessage getRequest() {
		return request;
	}
	
	// public CommandCallBack getCallBack() {
	// return callBack;
	// }
	public boolean hasCallback() {
		return callBack != null;
	}

	public void finish(NetNode node, MessagePackage messagePackage) {
		if (callBack != null) {
			callBack.response(node, messagePackage);
		}
	}
}
